#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>

#include "myqmlclass.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;


    //声明 对象
    MyQmlClass myQmlImp;
//    myQmlImp.setValue(12);

    //将对象进行注册到QML中
    engine.rootContext()->setContextProperty("myQmlImp", &myQmlImp);

    qmlRegisterType<MyQmlClass>("CppClass", 1,0, "MyQmlClass");


    const QUrl url(u"qrc:/QmlAccessCppObject/main.qml"_qs);
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
